import 'package:flutter/material.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/custom_password_field.dart';

///确认收货  支付底部框
class ConfirmPay extends StatefulWidget {
  @override
  _ConfirmPayState createState() => _ConfirmPayState();
}

class _ConfirmPayState extends State<ConfirmPay> {
  String passWord = ""; // 密码
  List<String> keyboard = ["1", "2", "3", "4", "5", "6", "4", "8", "9"]; //键盘
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onVerticalDragEnd: (onVerticalDragEnd) {},
      child: SingleChildScrollView(
        physics: NeverScrollableScrollPhysics(),
        child: SizedBox(
          height: setWidth(538),
          child: Stack(
            children: [
              Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(
                        margin: EdgeInsets.only(top: setWidth(19)),
                        child: Text(
                          "请输入支付密码",
                          style: TextStyle(
                              color: Color(0xff333333), fontSize: setSp(18)),
                        ),
                      ),
                    ],
                  ),
                  Container(
                    margin: EdgeInsets.only(
                        top: setWidth(19), bottom: setWidth(40)),
                    height: setWidth(0.5),
                    color: Color(0xffF0F0F0),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: setWidth(40)),
                    height: setWidth(49),
                    width: setWidth(345),
                    child: CustomPasswordField(passWord),
                  ),
                ],
              ),
              Align(
                alignment: Alignment.bottomCenter,
                child: Container(
                    color: Color(0xffE3E8EE),
                    height: setWidth(223),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Wrap(
                          children: keyboard
                              .asMap()
                              .map((key, value) {
                                return MapEntry(
                                    key,
                                    GestureDetector(
                                      onTap: () {
                                        if (passWord.length < 6) {
                                          setState(() {
                                            passWord = passWord + value;
                                          });
                                        }

                                        if (passWord.length == 6) {
                                          toast("支付成功");
                                          Navigator.pop(context);
                                          urlPush(context,
                                              "yuntu://goods_evaluate");
                                        }
                                      },
                                      child: Container(
                                          alignment: Alignment.center,
                                          width: setWidth(375) / 3,
                                          height: setWidth(56),
                                          decoration: BoxDecoration(
                                              color: Colors.white,
                                              border: Border(
                                                top: BorderSide(
                                                    color: Color(0xffE6E7E9),
                                                    width: setWidth(0.5)),
                                                right: BorderSide(
                                                    color: Color(0xffE6E7E9),
                                                    width: setWidth(0.5)),
                                              )),
                                          child: Text(
                                            value,
                                            style: TextStyle(
                                                color: Color(0xff333333),
                                                fontSize: setSp(30)),
                                          )),
                                    ));
                              })
                              .values
                              .toList(),
                        ),
                        Expanded(
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Expanded(
                                child: Container(
                                  width: setWidth(375) / 3,
                                  color: Color(0xffE3E8EE),
                                ),
                                flex: 1,
                              ),
                              Expanded(
                                child: GestureDetector(
                                  onTap: () {
                                    if (passWord.length < 6) {
                                      setState(() {
                                        passWord = passWord + "0";
                                      });
                                    } else {
                                      toast("密码超长");
                                    }
                                  },
                                  child: Container(
                                      alignment: Alignment.center,
                                      width: setWidth(375) / 3,
                                      height: setWidth(56),
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          border: Border.all(
                                              color: Color(0xffE6E7E9),
                                              width: setWidth(0.5))),
                                      child: Text(
                                        "0",
                                        style: TextStyle(
                                            color: Color(0xff333333),
                                            fontSize: setSp(30)),
                                      )),
                                ),
                                flex: 1,
                              ),
                              //删除
                              Expanded(
                                child: GestureDetector(
                                  onTap: () {
                                    if (passWord.length > 0) {
                                      setState(() {
                                        passWord = passWord.substring(
                                            0, passWord.length - 1);
                                      });
                                    } else {
                                      toast("请输入密码");
                                    }
                                    print(passWord);
                                  },
                                  child: Container(
                                    alignment: Alignment.center,
                                    color: Color(0xffE3E8EE),
                                    child: Image.asset(
                                      "assets/images/delete_password.png",
                                      width: setWidth(27),
                                      height: setWidth(19),
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                ),
                                flex: 1,
                              ),
                            ],
                          ),
                        )
                      ],
                    )),
              ),
              Positioned(
                  top: setWidth(20),
                  left: setWidth(18),
                  child: GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      Navigator.pop(context);
                    },
                    child: Container(
                      padding: EdgeInsets.all(setWidth(3)),
                      width: setWidth(21),
                      height: setWidth(21),
                      child: Image.asset("assets/images/pay_close.png",
                          fit: BoxFit.cover),
                    ),
                  )),
            ],
          ),
        ),
      ),
    );
  }
}
